
<template>
	<!-- 添加弹框 -->
		<el-dialog title="" visible :show-close="false" :append-to-body="true"  class="wrap">
        <i class="el-icon-close close" @click="cancel" style="color: white;z-index:10;"></i>
	    <div class="bt">报损添加</div>
	    <el-form label-width="100px" class="form">
		<el-form-item label="物品名称">
 			<el-input v-model="vwpid"  placeholder="请选择物品名称" icon="add" class="input"  v-if="false" ></el-input>
			<el-input v-model="vwpidmc" placeholder="请选择物品名称" icon="add" class="input"  :readonly="true"></el-input>
			<el-button  @click="componentsShow('xzwp')">选择物品</el-button>
 		</el-form-item>
		<el-form-item label="报损人员">
 			<el-select v-model="vbsr" class="select-block" >
                <el-option :label="v.zwm" :value="v.id" v-for="v in comboxlist"></el-option>
            </el-select>
 		</el-form-item>
		<el-form-item label="报损数量">
 				<el-input v-model="vsl"  placeholder="请输入数量" class="select-block"></el-input>
 		</el-form-item>
		<el-form-item label="报损原因">
 				<el-input v-model="vbsyy" type="textarea"  :rows="4"  placeholder="请输入报损原因" class="select-block"></el-input>
 		</el-form-item>
		<el-button type="primary" class="submit" @click="submit">保存</el-button>

		<Xzwplist v-if="portComponents.xzwp.toggle"  @close="componentsHide"  :data="portComponents.xzwp.data" :params="this.wpfl"></Xzwplist>
		<!--<Wpchooselist class="wpfl" @wpchoose="wpchooseed" @close="wpchoosecancel" v-if="showchoselist"  ></Wpchooselist>-->
		</el-form>
	</el-dialog>
</template>
<script type="text/javascript">
//	import Wpchooselist from '../wpfx/wpchooselist'
	import Xzwplist from './xzwp'
	import qs from 'qs'
	export default {
		props: ['params'],
		  components: { Xzwplist},
		data() {
			return {
				wpfl:'',
				showchoselist:false,
				vwpid: '',
				vwpidmc:'',
				vsl: '',
				vbsyy: '',
				vbsr: '',
//				vjsr: '',
				  comboxlist:[],
				dialogTableVisible: true,
				portComponents: {
						xzwp : {
								type: 'xzwp',
								toggle: false,
								params: '',
								data: {}
						}
				},
			}
		},
		created(){
//					 			 	alert(this.params)
		 	this.wpfl=this.params;
		 this.getcomboxlist();
	 },
		methods: {
			submit() {
				//检测
				this.$store.state.loading = true;
			    if(!this.vwpid) {
					this.$message.warning('请选择物品名称');
					this.$store.state.loading = false;
					return;
				}
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					wpid: this.vwpid,
					sl: this.vsl,
					bsyy: this.vbsyy,
					bsr: this.vbsr,
					jsr: this.vjsr,
					yhid: logininfo.id,
					xxid:logininfo.xxid
				});
				//执行
				this.axios.post(this.$store.state.api + 'wpbs/insert', params3)
					.then(res => {
						if(res.data.code == 1) {
						this.$message.success(res.data.msg);
							this.$emit('close', { type: 'add', cancel: false });
							this.$store.state.loading = false;
						} else {
						this.$message.warning(res.data.msg);
							this.$store.state.loading = false;
						}
					}).catch(res => {
						this.$message.danger("服务器繁忙，请重试");
						this.$store.state.loading = false;
					})
			},
			showwp(){
				this.showchoselist =true;
			},
			wpchooseed(josndata){
				this.vwpidmc = josndata.wpmc;

				this.vwpid=josndata.wpid;
						this.showchoselist=false;
			},
			wpchoosecancel(){
						this.showchoselist=false;
			},
			cancel() {
				this.$emit('close', { type: 'add', cancel: true })
			},
			getcomboxlist(){
					 var logininfo = JSON.parse(localStorage.logininfo) ;
				     this.searchLoading = true;
				     var params3 = qs.stringify({
							yhid: logininfo.id,
							xxid:logininfo.xxid
						});
				          this.axios.post(this.$store.state.api + 'ls/getzxls',params3)
									.then( res => {
				              let data = res.data.data;
				              let list = data.list;
				              this.comboxlist=list;
				          }).catch( res => {
				              this.searchLoading = false;
				          })
				        },
        				componentsShow (type,data) { //显示组件
						console.log(type,data)
						for ( let i in this.portComponents ) {
								if (type == this.portComponents[i].type) {
										console.log(this.portComponents[i])

										this.portComponents[i].toggle = true;
										this.portComponents[i].params = data;

										if (this.portComponents[i].data.type == 'single') {
												this.portComponents[i].data.index = data.row.id

										}else if(this.portComponents[i].data.type == 'multiple'){
												this.portComponents[i].data.index = this.multipleDelNum;

										}else{
												return;
										}
										return;
								}
						}

				},
				componentsHide (setting) { //关闭组件
					console.log()
						if(setting.data){
								this.vwpidmc = setting.data[0].mc
								this.vwpid = setting.data[0].id
								// this.vje = setting.data[0].jg
								for ( let i in this.portComponents ) {
										if (setting.type == this.portComponents[i].type) {
												this.portComponents[i].toggle = false;
												if (this.portComponents[i].type == 'singleDelete') {
														this.dataList.splice(setting.index,1)
												}
												return;
										}
								}
						}else{
							for ( let i in this.portComponents ) {
			                    if (setting.type == this.portComponents[i].type) {
			                        this.portComponents[i].toggle = false;
			                        if (!setting.cancel) {

			                        }
			                        return;
			                    }
			                }
						}
						}
		}
	}
</script>
<style lang="less" scoped>
	.wrap {
		.input-block {
			margin-bottom: 20px;
			text-align: center;
		}
		.bt{
		position: absolute;
		width: 100%;
		height: 50px;
		margin: 0 auto;
		top: 0;
		left: 0;
		background: #50BFFF;
		color:white;
		text-align:left;
		line-height: 50px;
		font-size: 17px;
		padding-left: 15px;
	}

.form {
	text-align: left;
	margin-top: 10px;
}
		.input {
			width: 62%;
			display: inline-block;
		}
		/*.input1 {
			width: 90%;
			display: inline-block;
		}
		.input2 {
			width: 90;
			display: inline-block;
			vertical-align: middle;
		}*/
		.input-block span {
			display: inline-block;
			width: 100px;
			text-align: right;
		}
		.select-block {
	// display: block;
	float: left;
	width: 85%;
}
		.submit {
			width: 120px;
			display: block;
			margin: 0 auto;
			margin-top: 20px;
		}
		.wpfl{
			background: #fff;
			position: absolute;
			top: 5px;
			left: 5px;
		}
	}
</style>
